package ro.cityprojects.adminloc.entities;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Set;

/**
 * Person class
 *
 * @author bogdan.solga
 * 
 * Date: 13.06.2013, time: 17:47
 */
@Entity
@NamedQueries({
    @NamedQuery(
        name = "Person.byUserName",
        query = "SELECT person FROM Person person WHERE person.userName = :userName"
    ),

    @NamedQuery(
        name = "Person.byName",
        query = "SELECT person FROM Person person WHERE lower(person.firstName) LIKE :name OR lower(person.lastName) LIKE :name"
    )
})
public class Person extends BaseEntity {

    @Id
    @javax.persistence.Column(name = "PERSON_ID", nullable = false, insertable = true, updatable = false, length = 0)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PERSON_SEQUENCE")
    @SequenceGenerator(name = "PERSON_SEQUENCE", sequenceName = "PERSON_ID_SEQUENCE", allocationSize = 5, initialValue = 5)
    private Integer id;

    public Integer getId() {
        return id;
    }

    public void setId(Integer personId) {
        this.id = personId;
    }

    @javax.persistence.Column(name = "USER_NAME", nullable = false, insertable = true, updatable = true, length = 32, precision = 0)
    private String userName;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @javax.persistence.Column(name = "FIRST_NAME", nullable = false, insertable = true, updatable = true, length = 32, precision = 0)
    private String firstName;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @javax.persistence.Column(name = "LAST_NAME", nullable = false, insertable = true, updatable = true, length = 32, precision = 0)
    private String lastName;

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @javax.persistence.Column(name = "PERSONAL_IDENTIFIER", nullable = false, insertable = true, updatable = true, length = 0)
    private BigDecimal personalIdentifier;

    public BigDecimal getPersonalIdentifier() {
        return personalIdentifier;
    }

    public void setPersonalIdentifier(BigDecimal personalIdentifier) {
        this.personalIdentifier = personalIdentifier;
    }

    @javax.persistence.Column(name = "AGE", nullable = true, insertable = true, updatable = true, length = 0)
    private Integer age;

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @javax.persistence.Column(name = "EMAIL", nullable = true, insertable = true, updatable = true, length = 32, precision = 0)
    private String email;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @javax.persistence.Column(name = "MOBILE_PHONE_NUMBER", nullable = true, insertable = true, updatable = true, length = 32, precision = 0)
    private String mobilePhoneNumber;

    public String getMobilePhoneNumber() {
        return mobilePhoneNumber;
    }

    public void setMobilePhoneNumber(String mobilePhoneNumber) {
        this.mobilePhoneNumber = mobilePhoneNumber;
    }

    @javax.persistence.Column(name = "HOME_PHONE_NUMBER", nullable = true, insertable = true, updatable = true, length = 32, precision = 0)
    private String homePhoneNumber;

    public String getHomePhoneNumber() {
        return homePhoneNumber;
    }

    public void setHomePhoneNumber(String homePhoneNumber) {
        this.homePhoneNumber = homePhoneNumber;
    }

    @OneToMany(mappedBy = "personByPersonId")
    private Set<PersonApartment> personApartmentsByPersonId;

    public Set<PersonApartment> getPersonApartmentsByPersonId() {
        return personApartmentsByPersonId;
    }

    public void setPersonApartmentsByPersonId(Set<PersonApartment> personApartmentsByPersonId) {
        this.personApartmentsByPersonId = personApartmentsByPersonId;
    }

    @OneToMany(mappedBy = "personByPersonId")
    private Set<PersonAssociation> personAssociationsByPersonId;

    public Set<PersonAssociation> getPersonAssociationsByPersonId() {
        return personAssociationsByPersonId;
    }

    public void setPersonAssociationsByPersonId(Set<PersonAssociation> personAssociationsByPersonId) {
        this.personAssociationsByPersonId = personAssociationsByPersonId;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Person{");
        sb.append("homePhoneNumber='").append(homePhoneNumber).append('\'');
        sb.append(", mobilePhoneNumber='").append(mobilePhoneNumber).append('\'');
        sb.append(", email='").append(email).append('\'');
        sb.append(", age=").append(age);
        sb.append(", personalIdentifier=").append(personalIdentifier);
        sb.append(", lastName='").append(lastName).append('\'');
        sb.append(", firstName='").append(firstName).append('\'');
        sb.append(", userName='").append(userName).append('\'');
        sb.append(", personId=").append(id);
        sb.append('}');
        return sb.toString();
    }
}
